package com.xuqm.sdhbwfu.app.viewmodel

import com.xuqm.base.App
import com.xuqm.base.common.GsonImplHelp
import com.xuqm.base.di.manager.HttpManager
import com.xuqm.base.extensions.putString
import com.xuqm.base.extensions.showMessage
import com.xuqm.sdhbwfu.app.common.SHARE_RISK_LOCATION
import com.xuqm.sdhbwfu.app.common.SHARE_RISK_PURE
import com.xuqm.sdhbwfu.app.repository.Service
import com.xuqm.sdhbwfu.core.extensions.io_main
import com.xuqm.sdhbwfu.core.extensions.subscribeBy
import com.xuqm.sdhbwfu.core.viewModel.BaseViewModel

class MainViewModel : BaseViewModel() {

    fun locationList() {
        HttpManager.getApi(Service::class.java)
            .locationList()
            .io_main()
            .subscribeBy(
                {
                    it?.also {
                        App.getInstance()
                            .putString(SHARE_RISK_LOCATION, GsonImplHelp.get().toJson(it))
                    }
                }, {
                    showMessage(it)
                }
            ).adds()
    }
    fun pureList() {
        HttpManager.getApi(Service::class.java)
            .pureList()
            .io_main()
            .subscribeBy(
                {
                    it?.also {
                        App.getInstance()
                            .putString(SHARE_RISK_PURE, GsonImplHelp.get().toJson(it))
                    }
                }, {
                    showMessage(it)
                }
            ).adds()
    }

}